<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <link rel="stylesheet" href="\homemobile\lib\reset.css">
  <link rel="stylesheet" href="\homemobile\lib\all.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vant@2.10/lib/index.css"/>
  <style>
    .rad{
        font-size: 14px;
    }
    .rad .van-radio__icon{
        font-size: 14px;
    }
    .title2{
        padding: 16px 16px 8px;
        color: #969799;
        font-size: 14px;
        line-height: 16px;
    }
    .van-uploader__upload{
        background: #fff;
        border: 1px solid #ccc;
    }
    .view{
        width: 60px;
        height: 60px;
        border: 1px solid #ccc;
    }
    .layui-upload-img{
      width:50px;
      height:50px;
    }
    img[src=""],img:not([src]){
      opacity:0;
    }
  </style>
</head>
<body>

<div id="app">
  <div class="van-nav-bar__content"><div class="van-nav-bar__title van-ellipsis">修改渠道码</div></div>
  <div class="pd">
    <div class="title">基础信息</div>
    <div class="mt rad">
      <van-cell-group>
        <van-field input-align="right"   v-model="codeName" label="二维码名称" id="name" placeholder="输入名称，仅内部可见"></van-field>
		<van-field input-align="right"   v-model="bz" label="备注" placeholder="输入备注信息"></van-field>
        <van-cell title="自动验证">
         <!-- <van-radio-group direction="horizontal" v-model="time">
            <van-radio name="1" >全天在线</van-radio>
            <van-radio name="2" >自动上下线</van-radio>
          </van-radio-group> -->
		  <van-radio-group direction="horizontal" v-model="time">
		    <van-radio name="1" >是</van-radio>
		    <van-radio name="2" >否</van-radio>
		  </van-radio-group>
        </van-cell>
        <van-cell title="使用人员" is-link @click="showTag = true">!{!{userTag}}</van-cell>
        <!-- <van-cell title="员工添加上线">
          <van-switch v-model="tag" size="18"></van-switch>
        </van-cell>
        <van-cell title="允许员工上下线">
          <van-switch v-model="tag" size="18"></van-switch>
        </van-cell>
        <van-cell title="备用员工" is-link @click="showTag = true">!{!{userTag}}</van-cell> -->
        <van-cell title="自动打标签">
          <van-switch v-model="tag" size="18"></van-switch>
        </van-cell>
        <van-cell title="客户标签:" is-link @click="showTags = true">!{!{userTags}}</van-cell>
      </van-cell-group>
    </div>
    <div class="mt title">欢迎语设置</div>

    <div class="mt">
      <div class="rad">
        <van-radio-group direction="horizontal" v-model="wecome">
          <van-radio name="1">渠道欢迎语</van-radio>
          <van-radio name="2">默认欢迎语</van-radio>
          <van-radio name="3">不发送欢迎语</van-radio>
        </van-radio-group>
      </div>
      <div class="mt">
        <van-notice-bar
            wrapable
            color="#333"
            background="#ecf9ff"
            :scrollable="false"
        >
          提示
        </van-notice-bar>
      </div>
      <div v-if="wecome==='1'">
        <van-cell-group title="欢迎语1">
          <van-field
              v-model="message"
              rows="2"
              autosize
              type="textarea"
              maxlength="50"
              placeholder="请输入"
              show-word-limit></van-field>
        </van-cell-group>
        <p class="title2">
          欢迎语2
        </p>
        <div class="rad">
          <van-radio-group v-model="type" direction="horizontal" >
			<van-radio name="1">无</van-radio>
            <van-radio name="2">图片</van-radio>
            <van-radio name="3">图文</van-radio>
            <van-radio name="4">小程序</van-radio>
            <!-- <van-radio name="4">表单</van-radio> -->
          </van-radio-group>
        </div>
        <div class="mt">
          <div v-if="type==='2'">
            <!-- <van-uploader v-model="fileList"></van-uploader> -->
            <div class="layui-input-block">
                <div class="layui-upload">
                  <div class="van-uploader__upload">
                    <button type="button" class="layui-btn" id="test1" onclick="uploads(); ">上传图片</button>
                  </div>
                    <input type="file" hidden id="files" />
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="demo1s" >
                        <input type="hidden" id="demo2s" name="file" />
                        <p id="demoText"></p>
                    </div>
                </div>
            </div>
          </div>
          <div v-if="type==='3'">
            <van-cell-group>
               <van-field input-align="right" v-model="codetitle" label="标题" placeholder="请输入"></van-field>
			         <van-field input-align="right" v-model="codeurl" label="链接" placeholder="请输入"></van-field>
			         <van-field input-align="right" v-model="codecontent" label="描述" placeholder="请输入"></van-field>
			  &nbsp;&nbsp;&nbsp;&nbsp;封面：
        <!-- <van-uploader v-model="codefile"></van-uploader> -->
              <div class="layui-input-block">
                <div class="layui-upload">
                  <div class="van-uploader__upload">
                    <button type="button" class="layui-btn" id="test1" onclick="uploads(); ">上传图片</button>
                  </div>
                    <input type="file" hidden id="files" />
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="demo1s" >
                        <input type="hidden" id="demo2s" name="file" />
                        <p id="demoText"></p>
                    </div>
                </div>
            </div>
            </van-cell-group>
          </div>
          <div v-if="type==='4'">
            <van-cell-group>
              <van-field input-align="right" v-model="weAppname" label="小程序名称" placeholder="请输入"></van-field>
              <van-field input-align="right" v-model="weAppid" label="小程序ID" placeholder="请输入"></van-field>
              <van-field input-align="right" v-model="weAppurl" label="小程序路径" placeholder="请输入"></van-field>
              <van-field input-align="right" v-model="weApptitle" label="小程序标题" placeholder="请输入"></van-field>
			  &nbsp;&nbsp;&nbsp;&nbsp;封面：
        <!-- <van-uploader v-model="weAppfile"></van-uploader> -->
            <div class="layui-input-block">
                <div class="layui-upload">
                  <div class="van-uploader__upload">
                    <button type="button" class="layui-btn" id="test1" onclick="uploads(); ">上传图片</button>
                  </div>
                    <input type="file" hidden id="files" />
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="demo1s" >
                        <input type="hidden" id="demo2s" name="file" />
                        <p id="demoText"></p>
                    </div>
                </div>
            </div>
            </van-cell-group>
          </div>
         <!-- <div v-if="type==='4'">
            表单 请自行根据业务需求开发
          </div> -->
        </div>
      <!--   <div class="mt">
          <van-cell-group>
            <van-cell title="欢迎语屏蔽">
              <van-switch v-model="wecomeStop" size="18"></van-switch>
            </van-cell>
            <van-cell title="分时段欢迎语">
              <van-switch v-model="wecomeStop" size="18"></van-switch>
            </van-cell>
          </van-cell-group>
          <div class="mt">
            <van-notice-bar
                wrapable
                color="#333"
                background="#ecf9ff"
                :scrollable="false"
            >
              开启后，客户昵称中包含设定的关键词的客户不会收到欢迎语，点击 <a href="#">查看</a>
            </van-notice-bar>
          </div>
        </div>
        <div class="title mt">
          其他设置
        </div>
        <div class="mt">
          <van-cell-group>
            <van-cell title="自动通过好友">
              <van-switch v-model="wecomeStop" size="18"></van-switch>
            </van-cell>
            <van-cell title="二维码浏览">
              <img class="view" src="\homemobile\lib\img\WX20201104-093312@2x.png" alt="">
            </van-cell>
            <van-cell title="更换二维码头像">
              <van-uploader :after-read="afterRead" >
                <van-button size="mini"  icon="plus" type="primary">上传文件</van-button>
              </van-uploader>
            </van-cell>
          </van-cell-group>
          <div class="mt">
            <van-notice-bar
                wrapable
                color="#333"
                background="#ecf9ff"
                :scrollable="false"
            >
              提示
            </van-notice-bar>
          </div>
        </div> -->
      </div>
    </div>

    <div class="mt">
     <van-button size="small" type="info"onclick="check()" block>修改渠道码</van-button>
    </div>
   <!--  <div class="mt">
      <a href="code.html"><van-button size="small" block>取消</van-button></a>
    </div> -->

  </div>

  <van-popup v-model="showTag">
    <div class="pd popup">
      <div class="title">请选择员工</div>
      <div class="mt">
        {loop $userList as $user}
			<input type="checkbox" name="user" id="username" value="{$user['id']}" />{$user['name']}
        {/loop}
        <van-button size="small" type="info" block onclick="que()">确定</van-button>	
      </div>
    </div>
  </van-popup>
  <van-popup v-model="showTags">
    <div class="pd popup">
      <div class="title">请选择客户标签</div>
      <div class="mt">
        {loop $etTagArr as $ettag}
		{loop json_decode($ettag['tags'],1) as $tag}
  			<input type="checkbox" name="users" id="username" value="{$tag['id']}" />{$tag['name']}
        {/loop}
		{/loop}
        <van-button size="small" type="info" block onclick="ques()">确定</van-button>	
      </div>
    </div>
  </van-popup>
</div>

<script src="\homemobile\lib\vue.js"></script>
<script src="\homemobile\lib\moment.js"></script>
<script src="/layui/layui.js"></script>
<script src="/js/ajax.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vant@2.10/lib/vant.min.js"></script>
<script>
var app = new Vue({
    el: '#app',
    data:{
      wecomeStop:true,
      tag:false,
      linkFind:true,
      codeName:'',
      codetitle:'',
      codeurl:'',
      bz:'',
      codecontent:'',
      weAppname:'',
      weAppid:'',
      weAppurl:'',
      weApptitle:'',
      userTag:'请选择',
      userTags:'请选择',
      showTag:false,
      showTags:false,
      wecome:'1',
      message:'',
      type:'0',
      time:'1',
      userTagse:'',
      userTage:'',
      fileList:[],
      weAppfile:[],
      codefile:[]
    },
    methods:{
        afterRead:function(file){
            console.log(file)
        },
        onSearch:function(){

        },
        setUserTag:function(item){
            this.userTag = item;
            this.showTag = false;
        },
    }
});
    app.$data.codeName = "{$contactWay->name}"; 
    app.$data.bz = "{$contactWay->bz}"; 
    app.$data.time = "{$contactWay->skip_verify}"; 
    app.$data.userTag = "{$strs}"; 
    app.$data.userTags = "{$tagdatas}"; 
    app.$data.message = "{$contactWay->text_content}"; 
    app.$data.codetitle = "{$contactWay->link_title}"; 
    app.$data.codeurl = "{$contactWay->link_url}"; 
    app.$data.codecontent = "{$contactWay->link_desc}";
    app.$data.weAppname = "{$contactWay->miniprogram_name}";
    app.$data.weAppid = "{$contactWay->miniprogram_appid}";
    app.$data.weAppurl = "{$contactWay->miniprogram_page}";
    app.$data.weApptitle = "{$contactWay->miniprogram_title}";
    app.$data.type = "{$contactWay->other_type}";
  	if('{$contactWay->auto_label}' == 1){
  		app.$data.tag = true;
  	}else{
  		app.$data.tag = false;
  	}
	function que(){
    var name=document.getElementsByName('user'); 
    var s='';
    for(var i=0; i<name.length; i++){
      if(name[i].checked) s+=name[i].value+','; //如果选中，将value添加到变量s中
    }
    app.$data.userTagess = s;
    myAjaxPost(false, true, 'users.html', {
      user:s
    }, function (resp) {
      if (resp.status == 'success') {
        app.$data.userTag = resp.data[0];
        app.$data.userTage = resp.data[1];
        app.$data.showTag = false;
      }
    });
  }
  function ques(){
    var name=document.getElementsByName('users'); 
    var s='';
    for(var i=0; i<name.length; i++){
      if(name[i].checked) s+=name[i].value+','; //如果选中，将value添加到变量s中
    }
    app.$data.userTagse = s;
    myAjaxPost(false, true, 'tags.html', {
      tags:s    
    }, function (resp) {
      if (resp.status == 'success') {
        app.$data.userTags = resp.data;
        app.$data.showTags = false;
      }
    });
  }

   function uploads() {
        $("#files").trigger("click");
        openuploads();
    }
   function openuploads() {
        $("#files").change(function () {
            var formdata = new FormData();
            formdata.append('file', $("#files")[0].files[0]); //获取图片信息
            // formdata.append('ordernumber'); //
            $.ajax({
                url: "upload_files.html",
                type: 'post',
                data: formdata,
                cache: false,
                dataType: 'json',
                processData: false,
                contentType: false,
                success: function (e) {
                    if (e.status == "success") {
                        var data = e.data.filePath;
                        $("#demo1s").attr('src',data);
                        $("#demo2s").attr('value',data);
                    } else {
                        alert(e.msg, '');
                    }
                }
            });
        });
	 }
  function check(){
  var codeName = app.$data.codeName;
    if(name == ""){
      codeName = "{$contactWay->name}"; 
    }
  var tag = app.$data.tag;
  var userTags = app.$data.userTagse;
    if(userTags == ""){
        userTags = '{$tagses}';
    }
  var radio = app.$data.time;
    if(radio == ""){
      radio = "{$contactWay->skip_verify}";
    }
  var usertage = app.$data.userTage;
    if(usertage == ""){
        usertage = "{$user_str_datas}"; 
    }
  var contents = app.$data.wecome;
  if(contents == 1){
    //第一条欢迎语
    wecome = 1;
    contents = app.$data.message;
      if(contents == ""){
         var contentse = "{$contactWay->text_content}";
      }
    //第二条欢迎语
    if(app.$data.type == 2){
      //图片
      var file = $("#demo2s").val();
      if(file == ""){
        file = "{$contactWay->image_url}";
      }
    }
    if(app.$data.type == 3){
      //图文
      var codetitle = app.$data.codetitle;
      var codeurl = app.$data.codeurl;
      var codecontent = app.$data.codecontent;
      if(codetitle==""){
        codetitle = "{$contactWay->link_title}"; 
      }
      if(codecontent==""){
        codecontent = "{$contactWay->link_desc}";
      }
      if(codeurl==""){
        codeurl = "{$contactWay->link_url}"; 
      }
      var codefiles = $("#demo2s").val();
      if(codefiles == ""){
        codefiles = "{$contactWay->link_picurl}";
      }
    }
    if(app.$data.type == 4){
      //小程序
      var weAppname = app.$data.weAppname;
      var weAppid = app.$data.weAppid;
      var weAppurl = app.$data.weAppurl;
      var weApptitle = app.$data.weApptitle;
      if(weApptitle==""){
        weApptitle = "{$contactWay->miniprogram_title}";
      }
      if(weAppurl==""){
        weAppurl = "{$contactWay->miniprogram_page}";
      }
      if(weAppname==""){
        weAppname = "{$contactWay->miniprogram_name}";
      }
      if(weAppid==""){
        weAppid = "{$contactWay->miniprogram_appid}";
      }
      var weAppfiles = $("#demo2s").val();
      if(weAppfiles == ""){
        weAppfiles = "{$contactWay->miniprogram_pic}";
      }
    }
  }
  if(contents == 2){
    wecome = 1;
    contentse = '例：您好，我是'+name+'客服！扫码下方二维码进群交流~ 如有问题，可随时咨询';
  }
  if(contents == 3){
    wecome = 0;
    contentse = "";
  }
  var userTagess = app.$data.userTagess;
  myAjaxPost(false, true, '', {
    name:codeName,
    auto_label:tag,
    checkLable:userTags,
    auto_welcome_msg:wecome,
    text_content:contentse,
    shareType:app.$data.type,
    image:file,
    link_title:codetitle,
    link_pic:codefiles,
    link_desc:codecontent,
    link_url:codeurl,
    miniprogram_title:weApptitle,
    miniprogram_name:weAppname,
    miniprogram_pic:weAppfiles,
    miniprogram_appid:weAppid,
    miniprogram_page:weAppurl,
    checkUser:usertage,
    bz:app.$data.bz,
    skip_verify:radio,
    userTagess:userTagess
  }, function (resp) {
    if (resp.status == 'success') {
      tusi(resp.msg);
      setTimeout(function(){
        location.href = 'code.html'; 
      },2000);
    }else{
      alert(resp.msg);
    }
  });
  
 }
 
 
</script>
</body>
</html>
